#######################################################################################
######     Inadvertent Expansion: How Peripheral Agents Shape World Politics     ######
######                             Replication File                              ######
#######################################################################################

# Analysis run using R version 4.3.1

rm(list=ls())

# Load required packages
require(plyr)
require(sandwich)
require(stargazer)

# Load data
data<-read.csv("INSERT FILE LOCATION ON YOUR HARD DRIVE/Inadvertent_expansion_data_v1.1.csv")


##############################################################################
#######     Chapter 2: Patterns of Inadvertent Expansion, 1816-2014     ######
##############################################################################

##########   Figures cited in book on p. 33   ##########

# Load Territorial Change data (tc2018.csv)
# (available at: https://correlatesofwar.org/data-sets/territorial-change)
datatc<-read.csv("INSERT FILE LOCATION ON YOUR HARD DRIVE/tc2018.csv")


# subset for conquest and annexation
datatc<-subset(datatc,procedur<=2)
# drop missing observations
datatc<-subset(datatc,procedur!=-9)
# drop cases where a state 'enters' the international system
datatc<-subset(datatc,entry==0)

# remove "." from population data
summary(datatc$pop)
datatc$pop[datatc$pop=="."]<-NA
datatc$pop<-as.numeric(paste(datatc$pop))

# remove "." from area data
summary(datatc$area)
datatc$area[datatc$area=="."]<-NA
datatc$area<-as.numeric(paste(datatc$area))

# separate out great power observations from the rest
USterr<-subset(datatc,gainer==2)
UKterr<-subset(datatc,gainer==200)
UKterr<-subset(UKterr,year<=1945)
FRterr<-subset(datatc,gainer==220)
FRterr<-subset(FRterr,year<=1940)
GMterr<-subset(datatc,gainer==255)
GMterr<-subset(GMterr,year<=1945)
AHterr<-subset(datatc,gainer==300)
AHterr<-subset(AHterr,year<=1918)
ITterr<-subset(datatc,gainer==325)
ITterr<-subset(ITterr,year<=1943)
RUterr<-subset(datatc,gainer==365)
CNterr<-subset(datatc,gainer==710)
JPterr<-subset(datatc,gainer==740)

# join them together
GPterr<-rbind(USterr,UKterr,FRterr,GMterr,AHterr,ITterr,RUterr,CNterr,JPterr)
rm(USterr,UKterr,FRterr,GMterr,AHterr,ITterr,RUterr,CNterr,JPterr)

# Great power share of territorial expansion observations
round(nrow(GPterr)/nrow(datatc), 2) # 0.76

# Great power share of territorial area gains through expansion
round(sum(GPterr$area,na.rm=T)/sum(datatc$area,na.rm=T), 2) # 0.79

# Great power share of population gains through expansion
round(sum(GPterr$pop,na.rm=T)/sum(datatc$pop,na.rm=T), 2) # 0.62



######   Table 2.1: Cases of Inadvertent Expansion (p. 38)   ######

# subset cases of inadvertent expansion
Table2.1<-subset(data,inadvertent==1)
# separate out relevant information
Table2.1<-cbind(Table2.1[4],Table2.1[2],Table2.1[3],Table2.1[8])



######   Figure 2.1: Intentional & Inadvertent Expansion by Year (p. 39)   ######

# create year base
Figure2.1<-as.data.frame(1816:2014)
names(Figure2.1)<-"year"

# separate observations of intentional and inadvertent
dataInadv<-subset(data,inadvertent==1)
dataIntent<-subset(data,inadvertent==0)

# Count year observations for each
dataInadv2<-count(dataInadv$year)
names(dataInadv2)<-c("year","inadvertent")
dataIntent2<-count(dataIntent$year)
names(dataIntent2)<-c("year","intentional")

# merge with year base
Figure2.1<-join(Figure2.1,dataInadv2)
Figure2.1<-join(Figure2.1,dataIntent2)

# remove extra data
rm(dataInadv2,dataIntent2)

# sub NAs for zero
Figure2.1[is.na(Figure2.1)]<-0

# figure created using Microsoft Excel



######   Figure 2.2: The Telegraph, Risk, & Inadvertent Expansion (p. 40)   ######

# Telegraph averages
mean(data$inadvertent[data$telegraph==1],na.rm=T) # 0.07633588
mean(data$inadvertent[data$telegraph==0],na.rm=T) # 0.375

# Telegraph significance test
lm1<-lm(inadvertent~telegraph,data=data)
robse1<-sqrt(diag(vcovHC(lm1,type="HC1")))

# Telegraph robust standard error
robse1[2] # 0.05011357

# Telegraph 95% confidence interval
qnorm(0.975)*robse1[2] # 0.0982208

# Risk averages
mean(data$inadvertent[data$risk==1],na.rm=T) # 0.09090909
mean(data$inadvertent[data$risk==0],na.rm=T) # 0.3214286

# Risk significance test
lm2<-lm(inadvertent~risk,data=data)
robse2<-sqrt(diag(vcovHC(lm2,type="HC1")))

# Risk robust standard error
robse2[2] # 0.04811334

# Risk 95% confidence interval
qnorm(0.975)*robse2[2] # 0.09430041

# figure created using Microsoft Excel



######   Table 2.2: intentional & Inadvertent Expansion by Variable (p. 40)   ######

# Generate variable names
Table2.2<-as.data.frame(c("year*",
                          "telegraph",
                          "risk",
                          "annexation",
                          "extra_regional",
                          "distance (km)",
                          "conflict",
                          "info_capacity",
                          "polity",
                          "democracy",
                          "autocracy",
                          "vdem_polyarchy",
                          "gainer_cinc"))
names(Table2.2)<-"Variable"

# Create data including only those that have been coded wrt inadvertent expansion
dataI2<-rbind(dataIntent,dataInadv)

# Generate minimum values in range
Table2.2<-cbind(Table2.2,round(c(min(dataI2$year),
                                 min(dataI2$telegraph,na.rm=T),
                                 min(dataI2$risk),
                                 min(dataI2$annexation),
                                 min(dataI2$extra_regional),
                                 min(dataI2$distance,na.rm=T),
                                 min(dataI2$conflict,na.rm=T),
                                 min(dataI2$info_capacity,na.rm=T),
                                 min(dataI2$polity,na.rm=T),
                                 min(dataI2$democracy),
                                 min(dataI2$autocracy),
                                 min(dataI2$vdem_polyarchy),
                                 min(dataI2$gainer_cinc,na.rm=T)),2))
colnames(Table2.2)[2]<-"Min"

# Generate maximum values in range
Table2.2<-cbind(Table2.2,round(c(max(dataI2$year),
                                 max(dataI2$telegraph,na.rm=T),
                                 max(dataI2$risk),
                                 max(dataI2$annexation),
                                 max(dataI2$extra_regional),
                                 max(dataI2$distance,na.rm=T),
                                 max(dataI2$conflict,na.rm=T),
                                 max(dataI2$info_capacity,na.rm=T),
                                 max(dataI2$polity,na.rm=T),
                                 max(dataI2$democracy),
                                 max(dataI2$autocracy),
                                 max(dataI2$vdem_polyarchy),
                                 max(dataI2$gainer_cinc,na.rm=T)),2))
colnames(Table2.2)[3]<-"Max"

# Generate average values for intentional expansion observations
Table2.2<-cbind(Table2.2,round(c(median(dataIntent$year),
                                 mean(dataIntent$telegraph,na.rm=T),
                                 mean(dataIntent$risk),
                                 mean(dataIntent$annexation),
                                 mean(dataIntent$extra_regional),
                                 mean(dataIntent$distance,na.rm=T),
                                 mean(dataIntent$conflict,na.rm=T),
                                 mean(dataIntent$info_capacity,na.rm=T),
                                 mean(dataIntent$polity,na.rm=T),
                                 mean(dataIntent$democracy),
                                 mean(dataIntent$autocracy),
                                 mean(dataIntent$vdem_polyarchy),
                                 mean(dataIntent$gainer_cinc,na.rm=T)),2))
colnames(Table2.2)[4]<-"Average (Intentional)"

# Generate average values for inadvertent expansion observations
Table2.2<-cbind(Table2.2,round(c(median(dataInadv$year),
                                 mean(dataInadv$telegraph,na.rm=T),
                                 mean(dataInadv$risk),
                                 mean(dataInadv$annexation),
                                 mean(dataInadv$extra_regional),
                                 mean(dataInadv$distance,na.rm=T),
                                 mean(dataInadv$conflict,na.rm=T),
                                 mean(dataInadv$info_capacity,na.rm=T),
                                 mean(dataInadv$polity,na.rm=T),
                                 mean(dataInadv$democracy),
                                 mean(dataInadv$autocracy),
                                 mean(dataInadv$vdem_polyarchy),
                                 mean(dataInadv$gainer_cinc,na.rm=T)),2))
colnames(Table2.2)[5]<-"Average (Inadvertent)"

# Generate differences between values for inadvertent and intentional expansion observations
Table2.2<-cbind(Table2.2,Table2.2[5]-Table2.2[4])
colnames(Table2.2)[6]<-"difference"

# Indicate missing data on each variable
Table2.2<-cbind(Table2.2,c(nrow(dataI2)-sum(is.na(dataI2$year)),
                           nrow(dataI2)-sum(is.na(dataI2$telegraph)),
                           nrow(dataI2)-sum(is.na(dataI2$risk)),
                           nrow(dataI2)-sum(is.na(dataI2$annexation)),
                           nrow(dataI2)-sum(is.na(dataI2$extra_regional)),
                           nrow(dataI2)-sum(is.na(dataI2$distance)),
                           nrow(dataI2)-sum(is.na(dataI2$conflict)),
                           nrow(dataI2)-sum(is.na(dataI2$info_capacity)),
                           nrow(dataI2)-sum(is.na(dataI2$polity)),
                           nrow(dataI2)-sum(is.na(dataI2$democracy)),
                           nrow(dataI2)-sum(is.na(dataI2$autocracy)),
                           nrow(dataI2)-sum(is.na(dataI2$vdem_polyarchy)),
                           nrow(dataI2)-sum(is.na(dataI2$gainer_cinc))))
colnames(Table2.2)[7]<-"n"



######   Table 2.3: Linear Probability Analysis of Inadvertent Expansion (p. 42)  ######

lm3<-lm(inadvertent~telegraph+risk+year+distance+conflict+annexation+info_capacity+democracy+gainer_cinc,data=data)
robse3<-sqrt(diag(vcovHC(lm3,type="HC1")))
stargazer(lm3, type="text",se=list(robse3),omit="Constant")




#######################################################################################
######     Inadvertent Expansion: How Peripheral Agents Shape World Politics     ######
######                              Online Appendix                              ######
#######################################################################################

######   Table A1: Balance Test for Case Selection   ######

# subset only inadvertent cases
dataI<-subset(data,inadvertent==1)

# subset qualitative cases selected for book
dataI1<-rbind(subset(dataI,id==1),subset(dataI,id==123),subset(dataI,id==124),subset(dataI,id==160),
              subset(dataI,id==204),subset(dataI,id==205),subset(dataI,id==247))

# subset qualitative cases not selected           
dataI2<-subset(dataI,id!=1)
dataI2<-subset(dataI2,id!=123)
dataI2<-subset(dataI2,id!=124)
dataI2<-subset(dataI2,id!=160)
dataI2<-subset(dataI2,id!=204)
dataI2<-subset(dataI2,id!=205)
dataI2<-subset(dataI2,id!=247)

# generate table
# first column (variable names)
TableA1<-as.data.frame(c("Year (median)",
                           "Regions (count)",
                           "Distance (km)",
                           "Extra_regional",
                           "Telegraph",
                           "Risk",
                           "Conflict",
                           "Annexation",
                           "Info_capacity",
                           "Democracy",
                           "Autocracy",
                           "Polity",
                           "VDem_Polyarchy",
                           "Gainer_CINC"))
names(TableA1)<-"variable"

# variable ranges (minimum)
TableA1<-cbind(TableA1,round(c(min(dataI$year),
                                   1,
                                   min(dataI$distance),
                                   min(dataI$extra_regional),
                                   min(dataI$telegraph,na.rm=T),
                                   min(dataI$risk),
                                   min(dataI$conflict),
                                   min(dataI$annexation),
                                   min(dataI$info_capacity),
                                   min(dataI$democracy),
                                   min(dataI$autocracy),
                                   min(dataI$polity),
                                   min(dataI$vdem_polyarchy),
                                   min(dataI$gainer_cinc)),2))
colnames(TableA1)[2]<-"min"

# variable ranges (maximum)
TableA1<-cbind(TableA1,round(c(max(dataI$year),
                                   length(unique(dataI$region)),
                                   max(dataI$distance),
                                   max(dataI$extra_regional),
                                   max(dataI$telegraph,na.rm=T),
                                   max(dataI$risk),
                                   max(dataI$conflict),
                                   max(dataI$annexation),
                                   max(dataI$info_capacity),
                                   max(dataI$democracy),
                                   max(dataI$autocracy),
                                   max(dataI$polity),
                                   max(dataI$vdem_polyarchy),
                                   max(dataI$gainer_cinc)),2))
colnames(TableA1)[3]<-"max"

# varables averages (selected cases)
TableA1<-cbind(TableA1,round(c(median(dataI1$year),
                                   length(unique(dataI1$region)),
                                   mean(dataI1$distance),
                                   mean(dataI1$extra_regional),
                                   mean(dataI1$telegraph,na.rm=T),
                                   mean(dataI1$risk),
                                   mean(dataI1$conflict),
                                   mean(dataI1$annexation),
                                   mean(dataI1$info_capacity),
                                   mean(dataI1$democracy),
                                   mean(dataI1$autocracy),
                                   mean(dataI1$polity),
                                   mean(dataI1$vdem_polyarchy),
                                   mean(dataI1$gainer_cinc)),2))
colnames(TableA1)[4]<-"cases (n=7)"

# variable averages (other cases)
TableA1<-cbind(TableA1,round(c(median(dataI2$year),
                                   length(unique(dataI2$region)),
                                   mean(dataI2$distance),
                                   mean(dataI2$extra_regional),
                                   mean(dataI2$telegraph,na.rm=T),
                                   mean(dataI2$risk),
                                   mean(dataI2$conflict),
                                   mean(dataI2$annexation),
                                   mean(dataI2$info_capacity),
                                   mean(dataI2$democracy),
                                   mean(dataI2$autocracy),
                                   mean(dataI2$polity),
                                   mean(dataI2$vdem_polyarchy),
                                   mean(dataI2$gainer_cinc)),2))
colnames(TableA1)[5]<-"rest of population (n=48)"

# average difference between selected and other cases
TableA1<-cbind(TableA1,TableA1[4]-TableA1[5])
colnames(TableA1)[6]<-"difference"

# remove extraneous data
rm(dataI,dataI1,dataI2)



######   Table A2.1: Missing Data on Inadvertent Expansion by Great Power   ######

# generate table

# create actor column
TableA2.1<-rbind(as.data.frame(unique(data$gainer)),"Total")
names(TableA2.1)<-"Actor"

# create great power years column
TableA2.1<-cbind(TableA2.1,c("1816-2014","1816-1945","1816-1940","1816-1945","1816-1918","1860-1943","1816-2014","1950-2014","1868-1945",""))
colnames(TableA2.1)[2]<-"Years"

# add how many observations have been coded
t1<-count(data$gainer[data$inadvertent>=0])
names(t1)<-c("Actor","Coded")
TableA2.1<-join(TableA2.1,t1)

# add how many total observations the actor has
TableA2.1[10,3]<-sum(TableA2.1$Coded,na.rm=T)
t2<-count(data$gainer)
names(t2)<-c("Actor","Total")
TableA2.1<-join(TableA2.1,t2)

# calculate percentage of all observations coded
TableA2.1[10,4]<-sum(TableA2.1$Total,na.rm=T)
TableA2.1<-cbind(TableA2.1,TableA2.1[3]/TableA2.1[4])
colnames(TableA2.1)[5]<-"Percent"
rm(t1,t2)



######   Table A2.2: Summary Statistics for Inadvertent Expansion Data   ######

# generate table

# create variable column
TableA2.2<-as.data.frame(c("year","inadavertent","telegraph","risk","annexation","conquest","extra_regional","distance",
                           "conflict","info_capacity","polity","democracy","autocracy","vdem_polyarchy","gainer_cinc"))
names(TableA2.2)<-"variable"

# create minimum value column
TableA2.2<-cbind(TableA2.2,round(c(min(data$year),
                                  min(data$inadvertent,na.rm=T),
                                  min(data$telegraph,na.rm=T),
                                  min(data$risk),
                                  min(data$annexation),
                                  min(data$conquest),
                                  min(data$extra_regional),
                                  min(data$distance),
                                  min(data$conflict),
                                  min(data$info_capacity,na.rm=T),
                                  min(data$polity),
                                  min(data$democracy),
                                  min(data$autocracy),
                                  min(data$vdem_polyarchy),
                                  min(data$gainer_cinc)),3))
colnames(TableA2.2)[2]<-"min"

# create maximum value column
TableA2.2<-cbind(TableA2.2,round(c(max(data$year),
                                   max(data$inadvertent,na.rm=T),
                                   max(data$telegraph,na.rm=T),
                                   max(data$risk),
                                   max(data$annexation),
                                   max(data$conquest),
                                   max(data$extra_regional),
                                   max(data$distance),
                                   max(data$conflict),
                                   max(data$info_capacity,na.rm=T),
                                   max(data$polity),
                                   max(data$democracy),
                                   max(data$autocracy),
                                   max(data$vdem_polyarchy),
                                   max(data$gainer_cinc)),3))
colnames(TableA2.2)[3]<-"max"

# create average value column
TableA2.2<-cbind(TableA2.2,round(c(mean(data$year),
                                   mean(data$inadvertent,na.rm=T),
                                   mean(data$telegraph,na.rm=T),
                                   mean(data$risk),
                                   mean(data$annexation),
                                   mean(data$conquest),
                                   mean(data$extra_regional),
                                   mean(data$distance),
                                   mean(data$conflict),
                                   mean(data$info_capacity,na.rm=T),
                                   mean(data$polity),
                                   mean(data$democracy),
                                   mean(data$autocracy),
                                   mean(data$vdem_polyarchy),
                                   mean(data$gainer_cinc)),3))
colnames(TableA2.2)[4]<-"mean"

# create difference column
TableA2.2<-cbind(TableA2.2,c(nrow(data)-sum(is.na(data$year)),
                            nrow(data)-sum(is.na(data$inadvertent)),
                            nrow(data)-sum(is.na(data$telegraph)),
                            nrow(data)-sum(is.na(data$risk)),
                            nrow(data)-sum(is.na(data$annexation)),
                            nrow(data)-sum(is.na(data$conquest)),
                            nrow(data)-sum(is.na(data$extra_regional)),
                            nrow(data)-sum(is.na(data$distance)),
                            nrow(data)-sum(is.na(data$conflict)),
                            nrow(data)-sum(is.na(data$info_capacity)),
                            nrow(data)-sum(is.na(data$polity)),
                            nrow(data)-sum(is.na(data$democracy)),
                            nrow(data)-sum(is.na(data$autocracy)),
                            nrow(data)-sum(is.na(data$vdem_polyarchy)),
                            nrow(data)-sum(is.na(data$gainer_cinc))))
colnames(TableA2.2)[5]<-"n"



######   Table A2.3: Inadvertent Expansion by Great Power   ######

# generate table

# Create actor column
TableA2.3<-as.data.frame(c("France","UK","Russia","Japan","Germany","USA","Austria","Italy","China"))
names(TableA2.3)<-"actor"

# Add inadvertent expansion observations
TableA2.3<-cbind(TableA2.3,c(nrow(subset(dataInadv,gainer_ccode==220)),
                           nrow(subset(dataInadv,gainer_ccode==200)),
                           nrow(subset(dataInadv,gainer_ccode==365)),
                           nrow(subset(dataInadv,gainer_ccode==740)),
                           nrow(subset(dataInadv,gainer_ccode==255)),
                           nrow(subset(dataInadv,gainer_ccode==2)),
                           nrow(subset(dataInadv,gainer_ccode==300)),
                           nrow(subset(dataInadv,gainer_ccode==325)),
                           nrow(subset(dataInadv,gainer_ccode==710))))
colnames(TableA2.3)[2]<-"inadvertent"

# Add total expansion observations
TableA2.3<-cbind(TableA2.3,c(nrow(subset(dataInadv,gainer_ccode==220))+nrow(subset(dataIntent,gainer_ccode==220)),
                           nrow(subset(dataInadv,gainer_ccode==200))+nrow(subset(dataIntent,gainer_ccode==200)),
                           nrow(subset(dataInadv,gainer_ccode==365))+nrow(subset(dataIntent,gainer_ccode==365)),
                           nrow(subset(dataInadv,gainer_ccode==740))+nrow(subset(dataIntent,gainer_ccode==740)),
                           nrow(subset(dataInadv,gainer_ccode==255))+nrow(subset(dataIntent,gainer_ccode==255)),
                           nrow(subset(dataInadv,gainer_ccode==2))+nrow(subset(dataIntent,gainer_ccode==2)),
                           nrow(subset(dataInadv,gainer_ccode==300))+nrow(subset(dataIntent,gainer_ccode==300)),
                           nrow(subset(dataInadv,gainer_ccode==325))+nrow(subset(dataIntent,gainer_ccode==325)),
                           nrow(subset(dataInadv,gainer_ccode==710))+nrow(subset(dataIntent,gainer_ccode==710))))
colnames(TableA2.3)[3]<-"total"                     

# Add rate of inadvertent expansion
TableA2.3<-cbind(TableA2.3,c(round(mean(data$inadvertent[data$gainer_ccode==220],na.rm=T),3),
                           round(mean(data$inadvertent[data$gainer_ccode==200],na.rm=T),3),
                           round(mean(data$inadvertent[data$gainer_ccode==365],na.rm=T),3),
                           round(mean(data$inadvertent[data$gainer_ccode==740],na.rm=T),3),
                           round(mean(data$inadvertent[data$gainer_ccode==255],na.rm=T),3),
                           round(mean(data$inadvertent[data$gainer_ccode==2],na.rm=T),3),
                           round(mean(data$inadvertent[data$gainer_ccode==300],na.rm=T),3),
                           round(mean(data$inadvertent[data$gainer_ccode==325],na.rm=T),3),
                           round(mean(data$inadvertent[data$gainer_ccode==710],na.rm=T),3)))
colnames(TableA2.3)[4]<-"rate"

# order by rate
TableA2.3<-TableA2.3[order(-TableA2.3$rate),]

# create bottom (total) row
TableA2.3a<-as.data.frame(cbind("Total",sum(TableA2.3$inadvertent)))
TableA2.3a<-as.data.frame(cbind("Total",sum(TableA2.3$inadvertent),sum(TableA2.3$total)))
TableA2.3a<-as.data.frame(cbind("Total",sum(TableA2.3$inadvertent),sum(TableA2.3$total),round(sum(TableA2.3$inadvertent)/sum(TableA2.3$total),3)))
names(TableA2.3a)<-c("actor","inadvertent","total","rate")

# append to table
TableA2.3<-rbind(TableA2.3,TableA2.3a)
rm(TableA2.3a)
names(TableA2.3)<-c("Actor","Inadvertent","Total","Percent")



######   Table A2.4: Inadvertent Expansion by Region   ######

# generate table

# create region column
TableA2.4<-as.data.frame(c("Sub-Saharan Africa","South & Central Asia","Asia-Pacific",
                          "Western Hemisphere","Middle East & North Africa","Europe"))
names(TableA2.4)<-"Region"

# add inadvertent expansion observations
TableA2.4<-cbind(TableA2.4,c(nrow(subset(dataInadv,region==3)),
                           nrow(subset(dataInadv,region==5)),
                           nrow(subset(dataInadv,region==6)),
                           nrow(subset(dataInadv,region==1)),
                           nrow(subset(dataInadv,region==4)),
                           nrow(subset(dataInadv,region==2))))
colnames(TableA2.4)[2]<-"Inadvertent"

# add total expansion observations
TableA2.4<-cbind(TableA2.4,c(nrow(subset(dataInadv,region==3))+nrow(subset(dataIntent,region==3)),
                           nrow(subset(dataInadv,region==5))+nrow(subset(dataIntent,region==5)),
                           nrow(subset(dataInadv,region==6))+nrow(subset(dataIntent,region==6)),
                           nrow(subset(dataInadv,region==1))+nrow(subset(dataIntent,region==1)),
                           nrow(subset(dataInadv,region==4))+nrow(subset(dataIntent,region==4)),
                           nrow(subset(dataInadv,region==2))+nrow(subset(dataIntent,region==2))))
colnames(TableA2.4)[3]<-"Total"  

# calculate percentage inadvertent
TableA2.4<-cbind(TableA2.4,round(TableA2.4[2]/TableA2.4[3],3))
colnames(TableA2.4)[4]<-"Percent"
TableA2.4<-TableA2.4[order(-TableA2.4$Percent),]



######   Table A2.5: Statistical Significance Tests for Telegraph, risk, & Inadvertent Expansion   ######

stargazer(lm1, lm2, type="text",se=list(robse1,robse2))



######   Table A2.6: Logistic Regression Analysis of Inadvertent Expansion   ######

glmr1<-glm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc,data=data, family=binomial(link="logit"))
robseglmr1<-sqrt(diag(vcovHC(glmr1,type="HC2")))
stargazer(glmr1,type="text",se=list(robseglmr1))



######   Table A2.7: Linear Probability Analysis with extra_regional   ######

lmr2<-lm(inadvertent~telegraph+risk+year+annexation+extra_regional+conflict+info_capacity+democracy+gainer_cinc,data=data)
robser2<-sqrt(diag(vcovHC(lmr2,type="HC1")))
stargazer(lmr2,type="text",se=list(robser2))



######   Table A2.8: Linear Probability Analysis with Alternative Regime Type Measures   ######

# autocracy dummy control
lmr3<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+autocracy+gainer_cinc,data=data)
robser3<-sqrt(diag(vcovHC(lmr3,type="HC1")))

# polity score control
lmr4<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+polity+gainer_cinc,data=data)
robser4<-sqrt(diag(vcovHC(lmr4,type="HC1")))

# v-dem polyarchy score control
lmr5<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+vdem_polyarchy+gainer_cinc,data=data)
robser5<-sqrt(diag(vcovHC(lmr5,type="HC1")))

stargazer(lmr3,lmr4,lmr5,type="text",se=list(robser3,robser4,robser5))



#####   Table A2.9 & A2.10: Linear Probability Analysis with Great Power Dummies   #####

# US dummy control
lmr6<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+us_dummy,data=data)
robser6<-sqrt(diag(vcovHC(lmr6,type="HC1")))

# UK dummy control
lmr7<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+uk_dummy,data=data)
robser7<-sqrt(diag(vcovHC(lmr7,type="HC1")))

# France dummy control
lmr8<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+france_dummy,data=data)
robser8<-sqrt(diag(vcovHC(lmr8,type="HC1")))

# Germany dummy control
lmr9<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+germany_dummy,data=data)
robser9<-sqrt(diag(vcovHC(lmr9,type="HC1")))

# Austria dummy control
lmr10<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+austria_dummy,data=data)
robser10<-sqrt(diag(vcovHC(lmr10,type="HC1")))

# Italy dummy control
lmr11<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+italy_dummy,data=data)
robser11<-sqrt(diag(vcovHC(lmr11,type="HC1")))

# Russia dummy control
lmr12<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+russia_dummy,data=data)
robser12<-sqrt(diag(vcovHC(lmr12,type="HC1")))

# China dummy control
lmr13<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+china_dummy,data=data)
robser13<-sqrt(diag(vcovHC(lmr13,type="HC1")))

# Japan dummy control
lmr14<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+japan_dummy,data=data)
robser14<-sqrt(diag(vcovHC(lmr14,type="HC1")))

# generate Table A2.9
stargazer(lmr6,lmr7,lmr8,lmr9,lmr10,type="text",se=list(robser6,robser7,robser8,robser9,robser10))

# generate Table A2.10
stargazer(lmr11,lmr12,lmr13,lmr14,type="text",se=list(robser11,robser12,robser13,robser14))



#####   Table A2.11: Linear Probability Analysis with Region Dummies   #####

# Western Hemisphere dummy control
lmr15<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+whemisphere_dummy,data=data)
robser15<-sqrt(diag(vcovHC(lmr15,type="HC1")))

# Europe dummy control
lmr16<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+europe_dummy,data=data)
robser16<-sqrt(diag(vcovHC(lmr16,type="HC1")))

# Africa dummy control
lmr17<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+africa_dummy,data=data)
robser17<-sqrt(diag(vcovHC(lmr17,type="HC1")))

# Middle East & North Africa dummy control
lmr18<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+mena_dummy,data=data)
robser18<-sqrt(diag(vcovHC(lmr18,type="HC1")))

# South & Central Asia dummy control
lmr19<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+scasia_dummy,data=data)
robser19<-sqrt(diag(vcovHC(lmr19,type="HC1")))

# Asia-Pacific dummy control
lmr20<-lm(inadvertent~telegraph+risk+year+annexation+distance+conflict+info_capacity+democracy+gainer_cinc+asiapac_dummy,data=data)
robser20<-sqrt(diag(vcovHC(lmr20,type="HC1")))

# generate Table A2.11
stargazer(lmr15,lmr16,lmr17,lmr18,lmr19,lmr20,type="text",se=list(robser15,robser16,robser17,robser18,robser19,robser20))

